<?php
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
session_start();
if (isset($_POST['openid']) && !empty($_POST['openid'])){
    include '../c/config.php';
    include 'thearray.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    $openid=addslashes(trim($_POST['openid']));
    $query=$mysqli->query("SELECT id,name,gao,weight,zubie,age FROM uinfo where openid='".$openid."' limit 0,1 ");
    $user=array();
    if($query->num_rows>0){
        $getUser=$query->fetch_assoc();
        $user=$getUser;
        if (isset($getUser['zubie'])){

            if (is_numeric($getUser['zubie'])){ 
                $user['zubie']=$zuBie[$getUser['zubie']]; 
            }else{
                $user['zubie']=$getUser['zubie'];
            }
        }else{
            $user['zubie']=getZuByAge($getUser['age']);
        }
    }
     
    $getUser=NULL;
    $user['fen']=0;
    $user['shenfen']=1;
    $user['isapply']=0; 
    $query=$mysqli->query("SELECT qiuid,weizhi,qiuhao,isapply FROM joinqiu where openid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
        $getJoin=$query->fetch_assoc();
        $queryQiu=$mysqli->query("SELECT name FROM qdui where id='".$getJoin['qiuid']."' limit 0,1 ");
        $getQiu=$queryQiu->fetch_assoc();
        
        $user['qiudui']='('.$getQiu['name'].')';
        if(0 == $getJoin['isapply']){
            $user['qiudui']='('.$getQiu['name'].')（审批中）';
        }
        if(2 == $getJoin['isapply']){    
            $user['qiudui']='('.$getQiu['name'].')（未通过审批）';
        }
        $user['qiuhao']=$getJoin['qiuhao'];
        $user['weizhi']=$weizhiList[$getJoin['weizhi']];
        $user['shenfen']=1; //球员
        $user['isapply']=$getJoin['isapply'];
    }
    
    $query=$mysqli->query("SELECT name,qiuhao FROM qdui where openid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
        $getQiu=$query->fetch_assoc();
        $user['qiudui']='('.$getQiu['name'].')';
        $user['qiuhao']=99;
        if ($getQiu['qiuhao']){
            $user['qiuhao']=$getQiu['qiuhao'];
        }
        $user['shenfen']=2; //队长
    }
    
    $msgTxt=$msgTitle='';
    $query=$mysqli->query("SELECT id,fromid,type FROM message where isread=0 and myid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
        $getMessage=$query->fetch_assoc();
        if (1 == $getMessage['type']){
            $querySend=$mysqli->query("SELECT name FROM uinfo where openid='".$getMessage['fromid']."' limit 0,1 ");
            $querySendName=$querySend->fetch_assoc();
            
            $msgTitle='球队加入提醒';
            $msgTxt=$querySendName['name'].'正请求加入您的球队';
            $mysqli->query("update message set isread=1 where id='".$getMessage['id']."'  ");
        }
        if (2 == $getMessage['type']){
            
            $query=$mysqli->query("SELECT name FROM qdui where openid='".$getMessage['fromid']."' limit 0,1 ");
            if($query->num_rows>0){
                $getQui=$query->fetch_assoc();
                $msgTitle='加入成功提醒';
                $msgTxt='您已成功加入'.$getQui['name'];
                $mysqli->query("update message set isread=1 where id='".$getMessage['id']."'  ");
            }
        }
    }
    $mysqli->close();
    
    echo json_encode(array('u'=>$user,'mt'=>$msgTxt,'mbt'=>$msgTitle));
}

